#!/usr/bin/env python
# encoding: utf-8

import sys
import logging


from lib.app_mysql import appMysql as db

reload(sys)
sys.setdefaultencoding("utf-8")

log = logging.getLogger("")
config = dict()
config["rules"] = list()


def init_rule():
    sql = "select rule, action from config;"
    db.autocommit(True)
    cursor = db.cursor()
    n = cursor.execute(sql)
    for row in cursor.fetchall():
        rule = dict(regex=row[0], action=row[1])
        if rule not in config["rules"]:
            config["rules"].append(rule)
    cursor.close()


def init_config():
    init_rule()